package robocup.component.actions;

import robocup.component.geometry.Vektor;
import robocup.component.math.RCMath;

/**
 * A turn neck action is used to turn the head into a different direction. Using
 * this, the agent can see other objects than those lying in fron of him. The
 * maximum angle can be at most [-90,90] degree relative to the players body
 * direction (else its neck is broken :-)
 */
public class TurnNeckAction
    extends Action {

  /**
   * The angle can be a value of [-180,180], but should not result in higher
   * values of [-90,90] relative to the body angle.
   */
  private double _angle;

  /**
   * Constructor - an action for turning the head direction
   * 
   * @param angle
   *          the angle to turn (-180, 180]
   */
  public TurnNeckAction(
      final double angle) {

    this._angle = RCMath.round(angle, Action.PARAMETER_PRECISION);
    this._type = TYPE.TURN_NECK;
  }

  /**
   * Returns the actions string representation:
   * 
   * @return (turn_neck &lt;angle&gt;)<br>
   *         <br>
   */
  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();
    buf.append("(turn_neck ");
    buf.append(Vektor.normalize(this._angle));
    buf.append(")");
    return buf.toString();
  }

  /**
   * @return Returns the angle.
   */
  public double getAngle() {

    return this._angle;
  }

  /**
   * An action is worth sending if it effects the world.
   * 
   * @return Returns true, if the angle is not equal to zero.
   */
  @Override
  public boolean isWorthSending() {

    return !(this._angle == 0);
  }

  /**
   * Sets a new angle to the command.
   * 
   * @param _angle -
   *          the new angle
   */
  public void setAngle(final double _angle) {

    this._angle = _angle;
  }

}
